<template>
  <div class="user-management">
    <!-- 顶部彩色圆点 -->
    <div class="status-dots">
      <span class="badge-dot bg-red"></span>
      <span class="badge-dot bg-yellow"></span>
      <span class="badge-dot bg-green"></span>
      <span class="badge-dot bg-blue"></span>
      <span class="badge-dot bg-gray"></span>
    </div>
    <!-- 添加用户管理文字 -->
    <div class="user-management-title">用户管理</div>

    <!-- 筛选和搜索区域 -->
    <div class="content-container">
      <el-row :gutter="24" class="filter-search-row" justify="flex-end">
        <el-col :span="8" class="filter-col">
          <span
              style="color: #000;font-size: 14px;width: 100%;
            text-align: center;line-height: 39px;border: 1px solid #DCDFE6;"
          >用户状态</span>
          <el-select
              v-model="select"
              placeholder="请选择任务状态"
              class="custom-select"
          >
            <el-option label="请选择" value="1"></el-option>
            <el-option label="正常" value="2"></el-option>
            <el-option label="限制" value="3"></el-option>
          </el-select>
        </el-col>
        <el-col :span="12" class="search-col">
          <el-input
              v-model="search"
              placeholder="请输入用户名"
              class="search-input"
          >
            <template #append>
              <el-button icon="el-icon-search" @click="searchUsers">搜索</el-button>
            </template>
          </el-input>
        </el-col>
      </el-row>

      <!-- 用户列表 -->
      <div class="user-list">
        <div class="list-header">
          <span>用户列表</span>
        </div>
        <div class="user-cards">
          <div class="card" v-for="(user, index) in users" :key="index">
            <div class="user-info">
              <span class="user-name">{{ user.name }}</span>
              <el-tag :type="user.status === '正常' ? 'success' : 'danger'">{{ user.status }}</el-tag>
              <span class="register-time">注册时间：{{ user.registerTime }}</span>
              <span class="balance">余额：{{ user.balance }}</span>
            </div>
            <div class="actions">
              <el-button size="small" round @click="restrictUser(user)">限制该用户状态</el-button>
              <el-button size="small" round @click="viewUserInfo(user)">用户信息及余额操作</el-button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 用户信息弹窗 -->
    <el-dialog title="用户信息" :visible.sync="dialogVisible">
      <el-form :model="userInfo" ref="userInfoForm" label-width="120px">
        <el-form-item label="用户编号">
          <el-input v-model="userInfo.id" disabled></el-input>
        </el-form-item>
        <el-form-item label="用户学号">
          <el-input v-model="userInfo.studentId"></el-input>
        </el-form-item>
        <el-form-item label="用户院校">
          <el-input v-model="userInfo.school"></el-input>
        </el-form-item>
        <el-form-item label="用户姓名">
          <el-input v-model="userInfo.name"></el-input>
        </el-form-item>
        <el-form-item label="用户性别">
          <el-select v-model="userInfo.gender">
            <el-option label="男" value="男"></el-option>
            <el-option label="女" value="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="注册时间">
          <el-input v-model="userInfo.registerTime" disabled></el-input>
        </el-form-item>
        <el-form-item label="用户状态">
          <el-select v-model="userInfo.status">
            <el-option label="正常" value="正常"></el-option>
            <el-option label="限制" value="限制"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="当前余额">
          <el-input v-model="userInfo.balance" disabled></el-input>
        </el-form-item>
        <el-form-item label="添加余额">
          <el-input v-model="addBalance" placeholder="请输入金额"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="success" @click="confirmAddBalance">确认添加</el-button>
        <el-button type="primary" @click="saveUserInfo">保存信息</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "AdminManagement",
  data() {
    return {
      select: '1', // 任务状态筛选
      search: '', // 搜索关键字
      users: [
        {
          id: 1, // 用户编号
          name: "小灰", // 用户名
          status: "正常", // 用户状态
          registerTime: "2024-12-17 16:41:33", // 注册时间
          balance: 1928, // 当前余额
          studentId: "xiaohui", // 用户学号
          school: "南昌大学", // 用户院校
          gender: "男", // 用户性别
        },
        {
          id: 2, // 用户编号
          name: "小灰", // 用户名
          status: "正常", // 用户状态
          registerTime: "2024-12-17 16:41:33", // 注册时间
          balance: 1928, // 当前余额
          studentId: "XH123456", // 用户学号
          school: "南昌大学", // 用户院校
          gender: "女", // 用户性别
        },
      ],
      userInfo: {}, // 当前查看的用户信息
      dialogVisible: false, // 弹窗显示状态
      addBalance: '', // 添加余额的输入框
      size: 'medium' // 描述列表的尺寸
    };
  },
  methods: {
    searchUsers() {
      // 搜索用户逻辑
      console.log("搜索用户：", this.search);
    },
    restrictUser(user) {
      // 限制用户状态逻辑
      user.status = user.status === "正常" ? "限制" : "正常";
      console.log("限制用户：", user);
    },
    viewUserInfo(user) {
      // 查看用户信息逻辑
      this.userInfo = user;
      this.dialogVisible = true;
    },
    confirmAddBalance() {
      // 确认添加余额逻辑
      if (this.addBalance) {
        this.userInfo.balance += parseFloat(this.addBalance);
        this.addBalance = '';
        console.log("添加余额后：", this.userInfo.balance);
      } else {
        console.log("请输入金额");
      }
    },
  },
};
</script>

<style scoped>
.user-management {
  padding: 20px;
}

.status-dots {
  display: flex;
  gap: 5px;
  margin-bottom: 10px;
}

.user-management-title {
  font-size: 20px;
  font-weight: normal;
  margin-bottom: 20px;
  margin-left: 60px;
}

.content-container {
  margin-left: 60px;
}

.badge-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.bg-red {
  background-color: #FF0000;
}

.bg-yellow {
  background-color: #FFD700;
}

.bg-green {
  background-color: #008000;
}

.bg-blue {
  background-color: #1E90FF;
}

.bg-gray {
  background-color: #808080;
}

.filter-search-row {
  margin-bottom: 20px;
}

.filter-col {
  display: flex;
  align-items: center;
}

.search-col {
  display: flex;
  align-items: center;
}

.search-input {
  width: 300px;
}

.user-list {
  border: 1px solid #dcdfe6;
  padding: 20px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sort-buttons {
  display: flex;
  gap: 10px;
}

.user-cards {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.card {
  padding: 15px;
  border: 1px solid #dcdfe6;
  border-radius: 5px;
}

.user-info {
  display: flex;
  gap: 10px;
  align-items: center;
}

.actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
}

.user-details {
  padding: 10px;
}
</style>